home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11538 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  78 lines

  1. Path: vixen.cso.uiuc.edu!usenet
  2. From: n-dade@uiuc.edu
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointer to interrupt method in BC 4.52
  5. Date: 15 Mar 1996 00:49:23 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4iaeqj$nli@vixen.cso.uiuc.edu>
  8. References: <4i9sho$3mj@masala.cc.uh.edu>
  9. Reply-To: n-dade@uiuc.edu
  10. NNTP-Posting-Host: homer.apr.uiuc.edu
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4i9sho$3mj@masala.cc.uh.edu>, pmn12564@Bayou.UH.EDU (pat neff) writes:
  14. >    I have a class in which one of the methods is an interrupt.  Since I need
  15. >to hook the interrupt into the interrupt table, I need a pointer to it.     
  16. >Something like:
  17. >
  18. >class myobject {
  19. >   void interrupt myinterrupt(...);
  20. >   void dohook ();
  21. >}
  22. >
  23. >void interrupt myobject::myinterrupt (...)
  24. >{
  25. >   // actual interrupt code here
  26. >}
  27. >
  28. >void myobject::dohook ()
  29. >{
  30. >   setvect (0x??, this->myinterrupt);
  31. >}
  32. >
  33. >     This compiler complains about the line with SETVECT saying I need to
  34. >call or take the address of the interrupt function.  I am trying to take the
  35. >address of course.  I have tried everything, but NO LUCK!  Can anyone out     
  36. >there help me? 
  37.  
  38. myinterrupt() is a member function of class myobject---you cannot call
  39. it with specifying which instance of myobject you are calling it with (in
  40. other words you have to define in some way what "this" will point to).
  41.  
  42. You have two possibilities:
  43. 1) make myinterrupt() a static member function of myobject. Then you
  44.    can call it without needing to specify an instance of myobject. The down
  45.    side is that you can't access any non-static variables of class myobject
  46.    (obviously).
  47. or
  48. 2) If you must access a non-static member variable in a specific myobject
  49. then make the myinterrupt a static member function, and make the pointer
  50. to that specific myobject a static member as well. Then you can access
  51. that myobject through the static pointer to it.
  52.  
  53. ie
  54.  
  55. class myobject {
  56.    int i;
  57.    static myobject*  interruptobject;
  58.    static void myinterrupt();
  59.    void dohook();
  60. };
  61.  
  62. myobject::interruptobject = new myobject;
  63.  
  64. void myobject::myinterrupt() {
  65.    cout << interruptobject->i; // or whatever you want
  66. }
  67.  
  68. void myobject::dohook() {
  69.    setvec(0x??, myinterrupt);
  70. }
  71.  
  72. If this doesn't make sense then look in your favorite C++ reference
  73. under "member pointers" (".*" and ".->")
  74.  
  75. -Nicolas Dade / n9rzb / nicolas-dade@uiuc.edu
  76.  
  77.  
  78.